package com.example.touch;

import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;

import android.graphics.Point;

import com.example.touch.domain.EventActionRule;

public class EventActionRegistry 
{
	private static HashMap<String, EventActionRule> eventActionRules = new HashMap<String, EventActionRule>();
	
	public static void triggerActions(Point currentPosition, Calendar now)
	{
		for(EventActionRule eaRule : eventActionRules.values())
		{
			if(eaRule.shouldTriggerActions(currentPosition, now))
				eaRule.invokeAllActions();
		}
	}
	
	public static void register(EventActionRule eaRule)
	{
		eventActionRules.put(eaRule.getID(), eaRule);
	}
	
	public static void registerAll(Collection<EventActionRule> eaRules)
	{
		for(EventActionRule eaRule : eaRules)
		{
			eventActionRules.put(eaRule.getID(), eaRule);
		}
	}
	
	public static EventActionRule getEventActionRule(String eID)
	{
		if(eventActionRules.containsKey(eID))
			return eventActionRules.get(eID);
		return null;
	}
	
	public static void removeEventActionRule(String eID)
	{
		if(eventActionRules.containsKey(eID))
			eventActionRules.remove(eID);
	}
}
